﻿<%@ WebHandler Language="C#" Class="Proxy" %>

using System;
using System.Web;
using park.cn.linkit.epark;

public class Proxy : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.Charset = "utf-8";
        context.Response.ContentType = "application/json";

        System.Web.SessionState.HttpSessionState Session = context.Session;

        string method = context.Request.Params["method"];        

        var request = context.Request;
        var response = context.Response;
        response.Charset = "utf-8";
        response.ContentType = "application/json";

        park.cn.linkit.epark.ServiceList sl = new park.cn.linkit.epark.ServiceList();
        
        string json = "{}";

        switch (method)
        {
            case "listCity":
                {
                    json = listCity(sl);
                    break;
                }
            case "listAreaByCity":
                {
                    json = listAreaByCity(request,sl);
                    break;
                }
            case "listStreetByArea":
                {
                    json = listStreetByArea(request, sl);
                    break;
                }
            case "listParking":
                {
                    json = ListParking(request, sl);
                    break;
                }
            case "listChargeRecord":
                {
                    json = ListChargeRecord(request, sl);
                    break; 
                }
            case "listEmployee":
                {
                    json = ListEmployee(sl);
                    break;
                }
            case "listInspectionRecordType":
                {
                    json = ListInspectionRecordType( sl);
                    break; 
                }
            case "listInspectionRecords":
                {
                    json = ListInspectionRecords(request, sl);
                    break; 
                }
            case "realTimeSchedulingEvents":
                {
                    json = RealTimeSchedulingEvents(request,sl);
                    break;
                }
                
        }


        response.Write(json);
        response.End();
    }

    /// <summary>
    /// 获取城区列表
    /// </summary>
    /// <returns></returns>
    public string listCity(ServiceList sl)
    {
        string json = sl.listCity();
        
        return json; 
    }
    /// <summary>
    /// 城区片区联动
    /// </summary>
    /// <param name="Request"></param>
    /// <returns></returns>
    public string listAreaByCity(HttpRequest Request,ServiceList sl)
    {
        int cityId = string.IsNullOrEmpty(Request.Params["cityId"]) ? 0 : int.Parse(Request.Params["cityId"]);

        string json = sl.listAreaByCity(cityId);
        return json; 
    }
    /// <summary>
    /// 片区街道联动
    /// </summary>
    /// <param name="Request"></param>
    /// <returns></returns>
    public string listStreetByArea(HttpRequest Request, ServiceList sl)
    {
        int areaId = string.IsNullOrEmpty(Request.Params["areaId"]) ? 0 : int.Parse(Request.Params["areaId"]);
        string json = sl.listStreetByArea(areaId);
        return json;
    }
    /// <summary>
    /// 指挥调度-停车监控-停泊记录
    /// </summary>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string ListParking(HttpRequest Request, ServiceList sl)
    {
        int cityId = string.IsNullOrEmpty(Request.Params["cityId"]) ? 0 : int.Parse(Request.Params["cityId"]);
        int areaId = string.IsNullOrEmpty(Request.Params["areaId"]) ? 0 : int.Parse(Request.Params["areaId"]);
        int streetId = string.IsNullOrEmpty(Request.Params["streetId"]) ? 0 : int.Parse(Request.Params["streetId"]);
        string startDate = Request.Params["startDate"];
        string endDate = Request.Params["endDate"];
        // resultType值列表：1.list(代表json数据列表输出) 2.xls(代表输出excel)
        string resultType = string.IsNullOrEmpty(Request.Params["resultType"]) ? "1" : Request.Params["resultType"];
        int page = string.IsNullOrEmpty(Request.Params["page"]) ? 0 : int.Parse(Request.Params["page"]);
        int size = string.IsNullOrEmpty(Request.Params["size"]) ? 0 : int.Parse(Request.Params["size"]);

       string json = sl.listParking(cityId, areaId, streetId, startDate, endDate, resultType, page, size);
       json = json.Replace("yes", "是").Replace("no", "否");
        return json;
    }

    /// <summary>
    /// 指挥调度-停车监控-收费记录
    /// </summary>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string ListChargeRecord(HttpRequest Request, ServiceList sl)
    {
        int cityId = string.IsNullOrEmpty(Request.Params["cityId"]) ? 0 : int.Parse(Request.Params["cityId"]);
        int areaId = string.IsNullOrEmpty(Request.Params["areaId"]) ? 0 : int.Parse(Request.Params["areaId"]);
        int streetId = string.IsNullOrEmpty(Request.Params["streetId"]) ? 0 : int.Parse(Request.Params["streetId"]);
        string startDate =Request.Params["startDate"];
        string endDate = Request.Params["endDate"];
        // resultType值列表：1.list(代表json数据列表输出) 2.xls(代表输出excel)
        string resultType = string.IsNullOrEmpty(Request.Params["resultType"]) ? "1" : Request.Params["resultType"];
        int page = string.IsNullOrEmpty(Request.Params["page"]) ? 0 : int.Parse(Request.Params["page"]);
        int size = string.IsNullOrEmpty(Request.Params["size"]) ? 0 : int.Parse(Request.Params["size"]);
        
        string json = sl.ListChargeRecord(cityId, areaId, streetId, startDate, endDate, resultType, page, size);
        json = json.Replace("yes", "是").Replace("no","否") ;
        return json;
    }
    /// <summary>
    /// 获取员工列表
    /// </summary>
    /// <param name="sl"></param>
    /// <returns></returns>
    private string ListEmployee(ServiceList sl)
    {
        string json = string.Empty; // "{\"listEmployee\":[{\"id\":\"1001\",\"name\":\"张二\"},{\"id\":\"1002\",\"name\":\"李四\"}]}";
        json = sl.ListEmployee();
        return json; 
    }
    
    /// <summary>
    /// 获取类型
    /// </summary>
    /// <returns></returns>
    private string ListInspectionRecordType( ServiceList sl)
    {
        string json = string.Empty; //"{\"listType\":[{\"id\":1,\"name\":\"已处理\"},{\"id\": 2,\"name\":\"贴罚单\"}]}";
        json = sl.ListInspectionRecordType();
        return json;    
    }

    private string ListInspectionRecords(HttpRequest Request,ServiceList sl)
    {
        int cityId = string.IsNullOrEmpty(Request.Params["cityId"]) ? 0 : int.Parse(Request.Params["cityId"]);
        int areaId = string.IsNullOrEmpty(Request.Params["areaId"]) ? 0 : int.Parse(Request.Params["areaId"]);
        int empId = string.IsNullOrEmpty(Request.Params["empId"]) ? 0 : int.Parse(Request.Params["empId"]);
        
        //int typeId = string.IsNullOrEmpty(Request.Params["typeId"]) ? 0 : int.Parse(Request.Params["typeId"]);
        int typeId = int.Parse(Request.Params["typeId"]);
        
        string startDate = Request.Params["startDate"];
        string endDate = Request.Params["endDate"];
        // resultType值列表：1.list(代表json数据列表输出) 2.xls(代表输出excel)
        string resultType = string.IsNullOrEmpty(Request.Params["resultType"]) ? "1" : Request.Params["resultType"];
        int page = string.IsNullOrEmpty(Request.Params["page"]) ? 0 : int.Parse(Request.Params["page"]);
        int size = string.IsNullOrEmpty(Request.Params["size"]) ? 0 : int.Parse(Request.Params["size"]);

        string json = String.Empty;
        json = sl.ListInspectionRecords(cityId, areaId, empId, typeId, startDate, endDate, page, size);
        return json;
    }


    private string RealTimeSchedulingEvents(HttpRequest Request, ServiceList sl)
    {
        int cityId = string.IsNullOrEmpty(Request.Params["cityId"]) ? 0 : int.Parse(Request.Params["cityId"]);
        int areaId = string.IsNullOrEmpty(Request.Params["areaId"]) ? 0 : int.Parse(Request.Params["areaId"]);
        int empId = string.IsNullOrEmpty(Request.Params["empId"]) ? 0 : int.Parse(Request.Params["empId"]);
        
        int typeId = string.IsNullOrEmpty(Request.Params["typeId"]) ? 0 : int.Parse(Request.Params["typeId"]);
        //string typeId = Request.Params["typeId"];
        
        string startDate = Request.Params["startDate"];
        string endDate = Request.Params["endDate"];
        // resultType值列表：1.list(代表json数据列表输出) 2.xls(代表输出excel)
        string resultType = string.IsNullOrEmpty(Request.Params["resultType"]) ? "1" : Request.Params["resultType"];
        int page = string.IsNullOrEmpty(Request.Params["page"]) ? 0 : int.Parse(Request.Params["page"]);
        int size = string.IsNullOrEmpty(Request.Params["size"]) ? 0 : int.Parse(Request.Params["size"]);

        string json = String.Empty;
        json = sl.listRealTimeSchedulingEvents(cityId, areaId, empId, typeId, startDate, endDate, page, size);
        return json;
    }
    
    
    
    public bool IsReusable {
        get {
            return false;
        }
    }
}